#! /usr/bin/python
# -*- coding:utf-8 -*-

## ========================================================================
## Copyright (C) 2007-2013  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ========================================================================

from config import *
from naviguation import *
from admin import *
from comics import *
import cgi
import os

form = cgi.FieldStorage()
cfg=CFG()

print u"Content-type: text/plain"
print

if form.has_key(u"session"): 
   session = form[u"session"].value

if form.has_key(u"config_id"): 
   config_id = form[u"config_id"].value
   config_id_default = cfg.readValue(u'config')
   if config_id_default == config_id:
     checked = "checked"
   else:
     checked = ""
else:
   config_id = cfg.readValue(u'config')
   checked = "checked"


# GET ADMIN CONTENT
adm=AdminCms()
print adm.getPageHeader()
print adm.getAdminMenu()


## GET CONTENT CONFIG
tag=Head()
tag.getHeadTags(config_id)
listTag=tag.getConfig()
select=tag.getHtmlSelectListID(config_id)

print """
	<tr><td colspan='3'><div id='active_page'><br/><h3>Configuration (%s)&nbsp;&nbsp;<a href='#' onclick='newConfig()' ><img src='/img/add_icon.gif' title='Nouvelle configuration' width='16' height='16' ></a></h3><br/>%s<br/>S&eacute;l&eacute;ctionner par defaut:&nbsp;<input type='checkbox' %s id='selected_id' value='1' /><br/><div id='msg_box'>&nbsp;</div>
	<table border='0' cellpadding='0' cellspacing='0' align='center'>
		<tr><td class='adminTitle'>Titre du site :</td></tr>
		<tr><td class='adminField'><input type='text' size='24' maxlength='30' id='title' value='%s'></td></tr>
		<tr><td class='adminTitle'>Slogan Pub :</td></tr>
		<tr><td class='adminField'><input type='text' size='24' maxlength='100' id='pub' value='%s'></td></tr>
		<tr><td class='adminTitle'>Description (meta) :</td></tr>
		<tr><td class='adminField'><input type='text' size='24' maxlength='250' id='description' value='%s'></td></tr>
		<tr><td class='adminTitle'>Mots clef (meta) :</td></tr>
		<tr><td class='adminField'><input type='text' size='24' maxlength='250' id='keyword' value='%s'></td></tr>
		<tr><td class='adminTitle'>URL du site :</td></tr>
		<tr><td class='adminField'><input type='text' size='24' maxlength='150' id='url' value='%s'></td></tr>
		<tr><td class='adminTitle'>Email de contact :</td></tr>
		<tr><td class='adminField'><input type='text' size='24' maxlength='150' id='email' value='%s'></td></tr>
		<tr><td class='adminTitle'>Texte bas de page :</td></tr>
		<tr><td class='adminField'><input type='text' size='24' maxlength='30' id='name' value='%s'></td></tr>
		<tr><td class='adminTitle'>Langue :</td></tr>
		<tr><td class='adminField'><input type='text' size='3'  maxlength='2' id='language' value='%s'></td></tr>
		<tr><td class='adminTitle'>Nom de la skin :</td></tr>
		<tr><td class='adminField'>
	"""% ( config_id, select, checked, listTag[u'title'], listTag[u'pub'], listTag[u'description'], listTag[u'keyword'], listTag[u'url'], listTag[u'email'], listTag[u'name'], listTag[u'language'] )

skin_path = u"%sskin" % Glob.SITE_PATH
skins_list = os.listdir(skin_path)
if len(skins_list) > 0:
	print "<select id='skin'>"
	for sk in skins_list:
		if sk == listTag[u'skin']:
			print "<option value='%s' selected>%s</option>"%( sk, sk)
		else:
			print "<option value='%s'>%s</option>"%( sk, sk)
	print "</select>"
else:
	print "Erreur skin"
	
print """
		</td></tr>
		<tr><td class='adminTitle'>Tag head supl&eacute;mentaire :</td></tr>
		<tr><td class='adminField'><input type='text' size='24' maxlength='250' id='headtag' value='%s'></td></tr>
	</table>
	<input type='hidden' id='config_id' value='%s'><input type='button' onclick='updateConfig()' value='Enregistrer' title='Sauvegarder les modifications'><input type='button' onclick='deleteConfig()' value='Supprimer' title='Supprimer la configuration'></div></td></tr>
	""" % (  listTag[u'headtag'], config_id )

print adm.getPagesList()
print adm.getPageFooter()
